package cn.itcast.controller;

import cn.itcast.j2cache.annotation.Cache;
import cn.itcast.j2cache.annotation.CacheEvictor;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.oschina.j2cache.CacheObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @author liangdi
 * @date 2021/8/22
 */
@RestController
@Api(tags = "声明式缓存测试")
@RequestMapping("j2cache")
public class MyJ2CacheController {
    @GetMapping("/getInfos")
    @ApiOperation("获取缓存")
    @Cache(key = "test")
    public List<String> getInfos() {
        List<String> data = new ArrayList<String>();
        data.add("info1");
        data.add("info2");
        return data;
    }

    /**
     * 清理指定缓存
     *
     * @return
     */
    @ApiOperation("清除缓存")
    @GetMapping("/evict")
    @CacheEvictor({@Cache(key = "test")})
    public String evict() {
        return "evict success";
    }

}
